// 干预记录详情页
const auth = require('../../../utils/auth');
const moment = require('../../../utils/moment');

Page({
  data: { id: null, loading: true, record: null, error: null },
  onLoad(options){
    if(options.id){ this.setData({id: options.id}); this.fetchDetail(); } else { this.setData({error:'参数错误', loading:false}); }
  },
  fetchDetail(){
    wx.request({
      url: `${getApp().globalData.apiBaseUrl}/intervention/${this.data.id}`,
      method: 'GET',
      header: { 'Authorization': `Bearer ${auth.getToken()}` },
      success: (res)=>{
        if(res.statusCode===401){ this.setData({error:'未登录或登录已过期', loading:false}); return; }
        if(res.statusCode===200 && res.data.success){ this.setData({record: res.data.data, loading:false}); }
        else { this.setData({error: (res.data && res.data.message)||'加载失败', loading:false}); }
      },
      fail: ()=> this.setData({error:'网络错误', loading:false})
    });
  },
  formatDate(d){ return d? moment(d).format('YYYY-MM-DD'):''; }
});
